package com.newgrand.annexserver.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.newgrand.annexserver.beans.Attachment;
import com.newgrand.annexserver.mapper.store.AttachmentMapper;
import com.newgrand.annexserver.service.AttachmentService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 附件表 服务实现类
 * </p>
 *
 * @author minyang
 * @since 2019-09-04
 */
@Service
public class AttachmentServiceImpl extends ServiceImpl<AttachmentMapper, Attachment> implements AttachmentService {

    @Autowired
    AttachmentMapper attachmentMapper;

    public Integer addAttachment() {
        Attachment attachment = new Attachment();
        attachment.setAsrFid("123456");
        attachment.setCreatetime(new Date());
        attachment.setUpdatetime(new Date());
        return attachmentMapper.insert(attachment);
    }

    public List getAttachmentList() {

        return attachmentMapper.selectList(new EntityWrapper<Attachment>().ge("phid", 1));
    }

    public Attachment getAttachmentByAsrfid(String asrfid) {
        List<Attachment> attachmentList = attachmentMapper.selectList(new EntityWrapper<Attachment>().ge("asr_fid", asrfid));
        if (attachmentList != null && attachmentList.size() > 0) {
            return attachmentList.get(0);
        }
        return null;
    }
}
